﻿using System;
using System.IO;
using viBlog.Classes;
using viBlog.Controllers;
using visinia.SmartEngine;
using visinia.SmartEngine.Site;

public partial class ClientScripts_viBlog_Comments_RenderComment : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(Request.QueryString["CommentId"] != null)
        {
            int commentid = 0;
            if (Int32.TryParse(Request.QueryString["CommentId"], out commentid))
            {
                Comment comment = CommentController.GetComment(commentid);
                CommentView commentview = (CommentView)LoadControl(GetCommentView());
                commentview.Comment = comment;
                Controls.Add(commentview);
            }
        }
    }

    private string GetCommentView()
    {
        // search for the CommentView.ascx 
        // 1 search in the current active theme folder
        //   if not found then
        // 2 search in the CommentsList module folder

        string currentThemeDir = Server.MapPath(WebRoots.GetThemesRoot) + SiteSettings.Theme;
        string file = currentThemeDir + "/viBlog.CommentView.ascx";
        if (File.Exists(file))
            return WebRoots.GetThemesRoot + SiteSettings.Theme + "/viBlog.CommentView.ascx";
        else
            return WebRoots.GetModulesRoot + "viBlog/CommentsList/viBlog.CommentView.ascx";
    }
}
